package com.basic.java.threads.priority;

/**
 * 测试线程优先级类
 * 创建时间：2022/4/19 21:18
 *
 * @author gejin
 */
public class TestPriority {
    public static void main(String[] args) {
        // 打印出主线程的优先级
        System.out.println(Thread.currentThread().getName() + "-------->" + Thread.currentThread().getPriority());
        MyThread thread = new MyThread();
        Thread t1 = new Thread(thread);
        Thread t2 = new Thread(thread);
        Thread t3 = new Thread(thread);
        Thread t4 = new Thread(thread);
        Thread t5 = new Thread(thread);
        Thread t6 = new Thread(thread);
        // 默认优先级
        t1.start();

        // 设置优先级小于默认值
        t2.setPriority(4);
        t2.start();

        // 设置优先级大于默认值
        t3.setPriority(7);
        t3.start();

        t4.setPriority(1);
        t4.start();

        t5.setPriority(8);
        t5.start();

        t6.setPriority(Thread.MAX_PRIORITY);
        t6.start();
    }
}

class MyThread implements Runnable {

    @Override
    public void run() {
        // 打印当前线程的优先级
        System.out.println(Thread.currentThread().getName() + "-------->" + Thread.currentThread().getPriority());
    }
}
